package com.bite.principle.component;

import com.bite.principle.model.Dog;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class BeanLifeComponent implements BeanNameAware {

    private Dog dog;

    public BeanLifeComponent() {
        System.out.println("执行构造函数...");
    }

    @Autowired
    public void setDog(Dog dog) {
        this.dog = dog;
        System.out.println("使用setter方法, 完成属性装配...");
    }

    @PostConstruct
    public void init(){
        System.out.println("执行init方法...");
    }

    @Override
    public void setBeanName(String name) {
        System.out.println("执行setBeanName, name:"+name);
    }

    public void use(){
        System.out.println("执行use方法....");
    }

    @PreDestroy
    public void destroy(){
        System.out.println("执行destroy方法...");
    }
}
